﻿Imports System.Reflection


Public Class RangeDataFilterType(Of T)
    Inherits DataFilterTypeBase(Of T)


    Protected Friend iValue1 As String = ""
    Protected Friend iValue2 As String = ""



    Public Property Value1() As String
        Get
            Return Me.iValue1
        End Get
        Set(ByVal value As String)
            Me.iValue1 = value
        End Set
    End Property

    Public Property Value2() As String
        Get
            Return Me.iValue2
        End Get
        Set(ByVal value As String)
            Me.iValue2 = value
        End Set
    End Property

    Public Sub New(ByVal TableName As String, ByVal FieldName As String, ByVal Value1 As String, ByVal Value2 As String)
        Me.iTable = TableName
        Me.iFieldName = FieldName
        Me.iValue1 = Value1
        Me.iValue2 = Value2
    End Sub

    Public Overrides Function ToString() As String
        Return Me.iFieldName & ": Between " & Me.iValue1 & " And " & Me.iValue2
    End Function

    Public Overrides Function GetSQL() As String
        Dim sql As String = ""
        If IsNothing(Me.iValue1) Then
            sql = " ([" & Me.iTable.ToString & "].[" & Me.iFieldName & "] Is NULL) "
        ElseIf IsDate(Me.iValue1.ToString) Then
            sql = " ([" & Me.iTable.ToString & "].[" & Me.iFieldName & "] Between " & _
                            "'" & Format(CType(Me.iValue1.ToString, DateTime), "yyyy-MMM-dd") & " 00:00:00.000' AND " & _
                            "'" & Format(CType(Me.iValue2.ToString, DateTime), "yyyy-MMM-dd") & " 23:59:59.999') "
        Else
            sql = " ([" & Me.iTable.ToString & "].[" & Me.iFieldName & "] Between " & _
                            "'" & Me.iValue1.ToString & "' AND " & _
                            "'" & Me.iValue2.ToString & "') "
        End If
        Return sql
    End Function

End Class

